//
//  RecommendViewController.m
//  LT
//
//  Created by dllo on 16/5/14.
//  Copyright © 2016年 dllo. All rights reserved.
//


//这个里面写三个不同的cell

#import "RecommendViewController.h"
#import "ZHScrollView.h"
#import "HotTripTableViewCell.h"
#import "NextFirstRowTableViewCell.h"
#import "NextSecondRowTableViewCell.h"
#import "NextThirdRowTableViewCell.h"
#import "DisThirdTableViewCell.h"
#import "DisFirstTableViewCell.h"
#import "DisSecondTableViewCell.h"

#import "RecommendModel.h"
#import "DisSubTwoModel.h"
#import "CarouselModel.h"
#import "DisTwoModel.h"
#import "ThirdLModel.h"
#import "NextFourModel.h"

#import "ScrollViewController.h"
#import "NextStationViewController.h"
#import "DiscountViewController.h"
#import "HotTripViewController.h"





#import "ZhuanTViewController.h"
#import "ZhuanTModel.h"
#import "TeJiaViewController.h"

#import "MJRefresh.h"


//菊花加载条
#import "MBProgressHUD.h"

#import "loginViewController.h"

#import "UIImageView+WebCache.h"

#define WIDTH self.view.frame.size.width

//=========静态============================================
static NSString *const nextFirstCell = @"nextFirstCell";
static NSString *const nextSecondCell = @"nextSecondCell";
static NSString *const nextThirdCell = @"nextThirdCell";

static NSString *const disFirstCell = @"disFirstCell";
static NSString *const disSecondCell = @"disSecondCell";
static NSString *const disThirdCell = @"disThirdCell";

static NSString *const hotTripCell = @"hotTripCell";

static NSString *const recommendCell = @"recommendCell";
//========================================================




@interface RecommendViewController ()<UITableViewDataSource,UITableViewDelegate>

@property(nonatomic,strong)UITableView *reTableView;

//建立传值所需要的各个控件的数组
@property(nonatomic,strong)NSMutableArray *allArray;//用来装recommend的
//用于缓存状态下读取recommend的数组
@property(nonatomic,strong)NSMutableArray *readArray;


@property(nonatomic,strong)NSMutableArray *CarouseArray;//装轮播图值得数组
//头视图需要改成全局属性,因为底下有方法要调用
@property(nonatomic,strong)UIView *headerView;

//为发现下一站的赋值准备一个数组
@property(nonatomic,strong)NSMutableArray *nstationArray;
//discount数组
@property(nonatomic,strong)NSMutableArray *discountArray;
//disCount_sub数组
@property(nonatomic,strong)NSMutableArray *disSubArray;
//hot数组"热门游记"
@property(nonatomic,strong)NSMutableArray *hotArray;
//装轮播图的URL
@property(nonatomic,strong)NSMutableArray *CarouseUrlArray;
//装下一站的URL数组
@property(nonatomic ,strong)NSMutableArray *nextUrlArray;

//刷新
@property (nonatomic, assign) BOOL isUpState;
//滚动视图
@property (nonatomic, retain) UIScrollView *scrollV;

//专题里面装的数组
@property(nonatomic ,strong)NSMutableArray *zhuanTArray;

//刷新 //一
@property(nonatomic,assign)NSInteger nextPage;//记录下一页,刷了几页.第一个屏幕还是第二个屏幕
@property(nonatomic,assign)BOOL isUpLoading;//标记上下拉操作,yes上拉

//刷新的时候放的动画图片
@property(nonatomic,strong)NSMutableArray *imageArray;


@end

@implementation RecommendViewController

//**********************   viewDidLoad  *******************
- (void)viewDidLoad {
    [super viewDidLoad];
   
    // Do any additional setup after loading the view.
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"btn_actionsheet"] forBarMetrics:UIBarMetricsDefault];
    //关闭半透明效果
    self.navigationController.navigationBar.translucent = NO;
    self.navigationItem.hidesBackButton = YES;
    //初始化数组
    self.allArray = [NSMutableArray array];
    self.CarouseArray = [NSMutableArray array];
    self.nstationArray = [NSMutableArray array];
    self.disSubArray = [NSMutableArray array];
    self.discountArray = [NSMutableArray array];
    self.hotArray = [NSMutableArray array];
    self.CarouseUrlArray = [NSMutableArray array];
    
    [self read];
    [self getData];

    //推荐页背景颜色
    self.view.backgroundColor = [UIColor whiteColor];
#pragma mark 建立RetableView
    self.reTableView = [[UITableView alloc]initWithFrame:[[UIScreen mainScreen]bounds] style:UITableViewStylePlain];
   [self.view addSubview:self.reTableView];
    self.reTableView.delegate = self;
    self.reTableView.dataSource = self;
    self.reTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    
  
//==============================轮播图==========================
    //增加头视图
    self.headerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 350 * WIDTHCELL)];
    self.headerView.backgroundColor = [UIColor colorWithRed:152/255.0 green:245/255.0 blue:255/255.0 alpha:1];
//    self.headerView.backgroundColor = [UIColor clearColor];
    //self.headerView.backgroundColor = [UIColor clearColor];
    self.reTableView.tableHeaderView = self.headerView;

//==============================userDefault==========================
//建立单例
//    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
//    //普遍形式
//    [defaults setObject:nil forKey:@"name"];
//    [defaults setObject:nil forKey:@"image"];
//     //判断是否是登录状态
//    [defaults setObject:@"0" forKey:@"isLogin"];
//    //存入网盘
//    [defaults synchronize];
    
    
//**********头视图处四个Button和对应label***************
    self.buttonType = [UIButton buttonWithType:UIButtonTypeCustom];
    self.buttonType.backgroundColor = [UIColor colorWithRed:240/255.0 green:255/255.0 blue:240/255.0 alpha:1];
    self.buttonType.frame = CGRectMake(20 * WIDTHCELL, 210* WIDTHCELL, 60* WIDTHCELL, 60* WIDTHCELL);
    self.buttonType.layer.masksToBounds = YES;
    self.buttonType.layer.cornerRadius = 30* WIDTHCELL;
    [self.buttonType setImage:[UIImage imageNamed:@"goodtype"] forState:UIControlStateNormal];
    [self.reTableView addSubview:self.buttonType];
    [self.buttonType addTarget:self action:@selector(buttonTypeAction:) forControlEvents:UIControlEventTouchUpInside];
    
    self.labelType = [[UILabel alloc]initWithFrame:CGRectMake(20* WIDTHCELL, 270* WIDTHCELL, 60* WIDTHCELL, 30* WIDTHCELL)];
    self.labelType.backgroundColor = [UIColor clearColor];
    self.labelType.text = @"看锦囊";
    self.labelType.textAlignment = NSTextAlignmentCenter;
    self.labelType.font = [UIFont systemFontOfSize:14];
    [self.reTableView addSubview:self.labelType];
  //=====
    
    
    self.buttonDis = [UIButton buttonWithType:UIButtonTypeCustom];
    self.buttonDis.backgroundColor = [UIColor colorWithRed:240/255.0 green:255/255.0 blue:240/255.0 alpha:1];
    self.buttonDis.frame = CGRectMake(120* WIDTHCELL, 210* WIDTHCELL, 60* WIDTHCELL, 60* WIDTHCELL);
    self.buttonDis.layer.masksToBounds = YES;
    self.buttonDis.layer.cornerRadius = 30* WIDTHCELL;
    [self.buttonDis setImage:[UIImage imageNamed:@"getdiscount"] forState:UIControlStateNormal];
    [self.reTableView addSubview:self.buttonDis];
    [self.buttonDis addTarget:self action:@selector(buttonDisAction:) forControlEvents:UIControlEventTouchUpInside];
    
    self.labelDis = [[UILabel alloc]initWithFrame:CGRectMake(120* WIDTHCELL, 270* WIDTHCELL, 60* WIDTHCELL, 30* WIDTHCELL)];
    self.labelDis.backgroundColor = [UIColor clearColor];
    self.labelDis.text = @"抢折扣";
    self.labelDis.textAlignment = NSTextAlignmentCenter;
      self.labelDis.font = [UIFont systemFontOfSize:14];
    [self.reTableView addSubview:self.labelDis];
 //=====
    
    self.buttonHotel = [UIButton buttonWithType:UIButtonTypeCustom];
    self.buttonHotel.backgroundColor = [UIColor colorWithRed:240/255.0 green:255/255.0 blue:240/255.0 alpha:1];
    self.buttonHotel.frame = CGRectMake(220* WIDTHCELL, 210* WIDTHCELL, 60* WIDTHCELL, 60* WIDTHCELL);
    self.buttonHotel.layer.masksToBounds = YES;
    self.buttonHotel.layer.cornerRadius = 30* WIDTHCELL;
    [self.buttonHotel setImage:[UIImage imageNamed:@"hotel"] forState:UIControlStateNormal];
    [self.reTableView addSubview:self.buttonHotel];
    [self.buttonHotel addTarget:self action:@selector(buttonHotelAction:) forControlEvents:UIControlEventTouchUpInside];
 
    self.labelHotel = [[UILabel alloc]initWithFrame:CGRectMake(220* WIDTHCELL, 270* WIDTHCELL, 60* WIDTHCELL, 30* WIDTHCELL)];
    self.labelHotel.backgroundColor = [UIColor clearColor];
    self.labelHotel.text = @"订酒店";
    self.labelHotel.textAlignment = NSTextAlignmentCenter;
    self.labelHotel.font = [UIFont systemFontOfSize:14];
    [self.reTableView addSubview:self.labelHotel];
 //=====
    self.buttonTrip = [UIButton buttonWithType:UIButtonTypeCustom];
    self.buttonTrip.backgroundColor = [UIColor colorWithRed:240/255.0 green:255/255.0 blue:240/255.0 alpha:1];
    self.buttonTrip.frame = CGRectMake(320 * WIDTHCELL, 210 * WIDTHCELL, 60 * WIDTHCELL, 60 * WIDTHCELL);
    self.buttonTrip.layer.masksToBounds = YES;
    self.buttonTrip.layer.cornerRadius = 30* WIDTHCELL;
    [self.buttonTrip setImage:[UIImage imageNamed:@"triping"] forState:UIControlStateNormal];
    [self.reTableView addSubview:self.buttonTrip];
    [self.buttonTrip addTarget:self action:@selector(buttonTripAction:) forControlEvents:UIControlEventTouchUpInside];
 
    self.labelTrip = [[UILabel alloc]initWithFrame:CGRectMake(320 * WIDTHCELL, 270 * WIDTHCELL, 60 * WIDTHCELL, 30 * WIDTHCELL)];
    self.labelTrip.backgroundColor = [UIColor clearColor];
    self.labelTrip.text = @"旅途中";
    self.labelTrip.textAlignment = NSTextAlignmentCenter;
    self.labelTrip.font = [UIFont systemFontOfSize:14];
    [self.reTableView addSubview:self.labelTrip];
//============================================================
    self.buttonHelp = [UIButton buttonWithType:UIButtonTypeCustom];
    self.buttonHelp.backgroundColor = [UIColor whiteColor];
    self.buttonHelp.frame = CGRectMake(0 * WIDTHCELL, 310 * WIDTHCELL, WIDTH, 40 * WIDTHCELL);
    [self.buttonHelp setTitle:@"点评我去过的目的地,帮助更多驴友er~~" forState:UIControlStateNormal];
    [self.buttonHelp setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
   //button字体大小更改
    self.buttonHelp.titleLabel.font = [UIFont systemFontOfSize: 14.0];
    
    [self.reTableView addSubview:self.buttonHelp];
    [self.buttonHelp addTarget:self action:@selector(buttonHelpAction:) forControlEvents:UIControlEventTouchUpInside];
  
//=============各个板块"注册"========================
   //一(1)"发现下一站"的第一种cell注册
    [self.reTableView registerClass:[NextFirstRowTableViewCell class] forCellReuseIdentifier:nextFirstCell];
    //-(2)"发现下一站"第二种cell注册
    [self.reTableView registerClass:[NextSecondRowTableViewCell class] forCellReuseIdentifier:nextSecondCell];
    //-(3)"发现下一站"第三种cell注册
    [self.reTableView registerClass:[NextThirdRowTableViewCell class] forCellReuseIdentifier:nextThirdCell];
//===
    //二(1)"抢折扣"第一种cell注册
    [self.reTableView registerClass:[DisFirstTableViewCell class] forCellReuseIdentifier:disFirstCell];
    //二(2)"抢折扣"第二种cell注册
    [self.reTableView registerClass:[DisSecondTableViewCell class] forCellReuseIdentifier:disSecondCell];
    //二(3)"抢折扣"第三种cell注册
    [self.reTableView registerClass:[DisThirdTableViewCell class] forCellReuseIdentifier:disThirdCell];
//===
//三:"热门游记"cell注册
    [self.reTableView registerClass:[HotTripTableViewCell class] forCellReuseIdentifier:hotTripCell];
//===================================================
    

    
    //菊花加载条
//    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    
    //刷新时的动画显示
    self.imageArray = [NSMutableArray array];
    for (int i = 1; i < 8; i++) {
        UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"%d",i]];
        [self.imageArray addObject:image];
    }
    
    
    
    //二.下拉刷新
    self.isUpLoading = NO;
    [self addFooter];
    [self addHeader];
    

    
}
//***************** END viewDidLoad ************************

#pragma mark -- 下拉刷新
-(void)addHeader{
//block中不能使用self.会报错
    __block RecommendViewController *recommendVC = self;
    
    MJRefreshGifHeader *MJHeader = [MJRefreshGifHeader headerWithRefreshingBlock:^{
       //记录页码
        recommendVC.nextPage = 1;
        //标记下拉刷新
        recommendVC.isUpLoading = NO;
        //请求数据
        [recommendVC getHotData:recommendVC.nextPage];
        
    }];
    //普通闲置状态
    [MJHeader setImages:self.imageArray forState:MJRefreshStateIdle];
    //松开就可以进行刷新的状态
    [MJHeader setImages:self.imageArray forState:MJRefreshStatePulling];
    //正在刷新中的状态
    [MJHeader setImages:self.imageArray forState:MJRefreshStateRefreshing];
    
    self.reTableView.mj_header = MJHeader;


}


#pragma mark -- 上拉加载更多
-(void)addFooter{
    
    __block RecommendViewController *recommendVC = self;
    //添加上拉刷新尾部控件
    
    MJRefreshAutoGifFooter *footer = [MJRefreshAutoGifFooter footerWithRefreshingBlock:^{
        //上拉一次自增一次
        recommendVC.nextPage ++;
        //标记为上拉操作
        recommendVC.isUpLoading = YES;
        //请求数据
        [recommendVC getHotData:recommendVC.nextPage];
        
    }];
    
    [footer setImages:self.imageArray forState:MJRefreshStateRefreshing];
    self.reTableView.mj_footer = footer;
    
    
}

//************缓存的读取数据*************
-(void)read{

    
    self.readArray = [NSMutableArray array];
    
 //取数据从本地plist
    
    NSString *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).lastObject;
    NSString *recommendPath = [path stringByAppendingPathComponent:@"Recommend.plist"];
    NSDictionary *localRecommendDic = [NSDictionary  dictionaryWithContentsOfFile:recommendPath];
    
    if (localRecommendDic.count != 0) {
        //KVC赋值
        RecommendModel *recommend = [[RecommendModel alloc]init];
        [recommend setValuesForKeysWithDictionary:localRecommendDic];
        [self.allArray addObject:recommend];
        
        //轮播图赋值
        for (CarouselModel *slide in recommend.slide) {
            [self.CarouseArray addObject:slide.photo];
            [self.CarouseUrlArray addObject:slide.url];
        }
        //轮播图的方法
        [self getZHScrollViewData];
        
        //"发现下一站"赋值
        self.nstationArray = [NSMutableArray arrayWithArray:recommend.subject];
        
        //discount赋值
        self.discountArray = [NSMutableArray arrayWithArray:recommend.discount];
        //discount_sub 赋值
        self.disSubArray = [NSMutableArray arrayWithArray:recommend.discount_subject];
        
        
        //刷新tableView
      //  [self.reTableView reloadData];
        
        //隐藏菊花加载条?????????????????跳进专题之后就会有bug
      //  [MBProgressHUD hideHUDForView:self.view animated:YES];
    }

    

    NSString *hotArrayPath = [path stringByAppendingPathComponent:@"hotData.plist"];
    NSArray *hotArray = [NSArray  arrayWithContentsOfFile:hotArrayPath];
    
    if (hotArray.count != 0) {
        
        for (NSDictionary *hotDataDic in hotArray) {
            ThirdLModel *hotModel = [[ThirdLModel alloc]init];
            [hotModel setValuesForKeysWithDictionary:hotDataDic];
            [self.hotArray addObject:hotModel];
            
        }
      //  NSLog(@"%@", hotDataArray);
        
        //停止上下刷新
        [self.reTableView.mj_footer endRefreshing];
        [self.reTableView.mj_header endRefreshing];
        
        
       // [self.reTableView reloadData];

    }

    [self.reTableView reloadData];
    //隐藏菊花加载条?????????????????跳进专题之后就会有bug
    //[MBProgressHUD hideHUDForView:self.view animated:YES];
    
}




-(void)getData{

    //GET请求
    [ZHNetworking zhGETWithURL:@"http://open.qyer.com/qyer/recommands/entry?client_id=qyer_ios&client_secret=cd254439208ab658ddf9&count=20&lat=38.88256929626057&lon=121.5393328309779&page=1&track_app_channel=App%2520Store&track_app_version=6.8.5&track_device_info=iPhone%25205s&track_deviceid=CBF73BD2-C65E-4BC1-9574-89BDE1EE9C36&track_os=ios%25209.2.1&v=1" parameter:nil succes:^(id result) {
        
        NSDictionary *dic = result;
        NSDictionary *dataDic = [dic objectForKey:@"data"];
         //存入缓存
        //找Document路径
        NSString *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).lastObject;
        NSLog(@"%@",path);
        //拼接我们自己定义的路径(自己定义,与其他路径区分开,路径相同会覆盖)
        NSString *dataDicPath = [path stringByAppendingPathComponent:@"Recommend.plist"];
        
        //写入数据到对应路径的plist文件中
        [dataDic writeToFile:dataDicPath atomically:YES];
        //KVC赋值
        RecommendModel *recommend = [[RecommendModel alloc]init];
        [recommend setValuesForKeysWithDictionary:dataDic];
        [self.allArray addObject:recommend];
        
        //轮播图赋值
        for (CarouselModel *slide in recommend.slide) {
            [self.CarouseArray addObject:slide.photo];
            [self.CarouseUrlArray addObject:slide.url];
        }
        //轮播图的方法
        [self getZHScrollViewData];
        
        //"发现下一站"赋值
        self.nstationArray = [NSMutableArray arrayWithArray:recommend.subject];
        
        //discount赋值
        self.discountArray = [NSMutableArray arrayWithArray:recommend.discount];
        //discount_sub 赋值
        self.disSubArray = [NSMutableArray arrayWithArray:recommend.discount_subject];
        
   
        //刷新tableView
        [self.reTableView reloadData];
        //菊花加载条
        [MBProgressHUD showHUDAddedTo:self.view animated:YES];
        //隐藏菊花加载条?????????????????跳进专题之后就会有bug
        [MBProgressHUD hideHUDForView:self.view animated:YES];
        
        
        [[NSUserDefaults standardUserDefaults]setObject:@"1" forKey:@"netStatus"];
        
        
    } failure:^(NSError *error) {

    }];
}

//获取hot界面的数据
//hotTravel
-(void)getHotData:(NSInteger)nextPage{
    
    [ZHNetworking zhGETWithURL:@"http://open.qyer.com/qyer/recommands/trip?client_id=qyer_android&client_secret=9fcaae8aefc4f9ac4915&v=1&track_deviceid=867323023990045&track_app_version=6.7.1&track_app_channel=xiaomi&track_device_info=cancro&track_os=Android4.4.4&app_installtime=1443411950696&lat=38.883872&lon=121.544701&type=index&page=2&count=10" parameter:nil succes:^(id result) {
        NSDictionary *hotDic = result;
        NSMutableArray *hotDataArray = [hotDic objectForKey:@"data"];
        
        //存入缓存
        //找Document路径
        NSString *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).lastObject;
        NSLog(@"%@",path);
        //拼接我们自己定义的路径(自己定义,与其他路径区分开,路径相同会覆盖)
        NSString *hotArrayPath = [path stringByAppendingPathComponent:@"hotData.plist"];
        
        //写入数据到对应路径的plist文件中
        [hotDataArray writeToFile:hotArrayPath atomically:YES];
        
        for (NSDictionary *hotDataDic in hotDataArray) {
            ThirdLModel *hotModel = [[ThirdLModel alloc]init];
            [hotModel setValuesForKeysWithDictionary:hotDataDic];
            [self.hotArray addObject:hotModel];
            
        }
        NSLog(@"%@", hotDataArray);
        
        //停止上下刷新
        [self.reTableView.mj_footer endRefreshing];
        [self.reTableView.mj_header endRefreshing];
        
       
        [self.reTableView reloadData];
        
        
    } failure:^(NSError *error) {
   
        
    }];
   
}





//轮播图
-(void)getZHScrollViewData{

    ZHScrollView *zhscroll = [[ZHScrollView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 200 * WIDTHCELL)];
    [zhscroll setImages:self.CarouseArray];
    //含义?
    __block RecommendViewController *recommendVC = self;
    //吧之前准备好的block方法添加到scroll中
    [zhscroll setScrollBlock:^(NSInteger index) {
        ScrollViewController *scrollVC = [[ScrollViewController alloc]init];
        UINavigationController *scrollNa = [[UINavigationController alloc]initWithRootViewController:scrollVC];
        scrollVC.sliderString = [recommendVC.CarouseUrlArray objectAtIndex:index];
       NSLog(@"--%@",recommendVC.CarouseUrlArray);
        [recommendVC presentViewController:scrollNa animated:YES completion:^{
            
            
        }];
        
    }];
    
    [self.headerView addSubview:zhscroll];


}


//============五个头视图button的点击方法==========
-(void)buttonTypeAction:(UIButton *)button{
    //NSLog(@"看锦囊");
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"数据维护!" message:nil preferredStyle:UIAlertControllerStyleAlert];
    
    [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil]];
    [self presentViewController:alert animated:YES completion:nil];
    

}

-(void)buttonDisAction:(UIButton *)button{
    
    NSLog(@"抢折扣");
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"数据维护!" message:nil preferredStyle:UIAlertControllerStyleAlert];
    
    [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil]];
    [self presentViewController:alert animated:YES completion:nil];
    
    
    
}

-(void)buttonHotelAction:(UIButton *)button{
    
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"数据维护!" message:nil preferredStyle:UIAlertControllerStyleAlert];
    
    [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil]];
    [self presentViewController:alert animated:YES completion:nil];
    
    
}

-(void)buttonTripAction:(UIButton *)button{
    
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"数据维护!" message:nil preferredStyle:UIAlertControllerStyleAlert];
    
    [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil]];
    [self presentViewController:alert animated:YES completion:nil];
    
    
}

-(void)buttonHelpAction:(UIButton *)button{
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"数据维护!" message:nil preferredStyle:UIAlertControllerStyleAlert];
    
    [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil]];
    [self presentViewController:alert animated:YES completion:nil];
    

}

//=============================
#pragma mark 设置分区行高
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        if (indexPath.row == 0) {
            return 190* WIDTHCELL;
        }else if (indexPath.row == 1){
            return 190* WIDTHCELL;
        
        }
        return 50* WIDTHCELL;
        
    }else if (indexPath.section == 1){
        if (indexPath.row == 0) {
            return 190* WIDTHCELL;
        }else if (indexPath.row == 1){
        
            return 400* WIDTHCELL;
        }
        return 50* WIDTHCELL;
    }
    
    
    return 120* WIDTHCELL;
}

#pragma mark 设置section数量
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 3;

}

#pragma mark 设置section标题
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
    if (section == 0) {
        return @"发现下一站";
        
    }else if (section == 1){
    
    return @"抢特价折扣";
    
    }
    return @"看热门游记";

   
}
//========cell的点击方法================================
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

    if (indexPath.section == 0) {
        if (indexPath.row == 0) {
            NextStationViewController *nextVC = [[NextStationViewController alloc]init];
            UINavigationController *nextNa = [[UINavigationController alloc]initWithRootViewController:nextVC];
            NextFourModel *nextModel = [self.nstationArray firstObject];
            nextVC.navigationItem.title = nextModel.title;
            nextVC.nextString = nextModel.url;
            [self presentViewController:nextNa animated:YES completion:^{
                
                
            }];
            
        }else if (indexPath.row == 2){
            ZhuanTViewController *zhuanTVC = [[ZhuanTViewController alloc]init];
            UINavigationController *zhuanTNa = [[UINavigationController alloc]initWithRootViewController:zhuanTVC];
            [self presentViewController:zhuanTNa animated:YES completion:^{
                
            }];
                
        }
        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"数据维护!" message:nil preferredStyle:UIAlertControllerStyleAlert];
        
        [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil]];
        [self presentViewController:alert animated:YES completion:nil];
        
    
    }
    else if (indexPath.section == 1){
        if (indexPath.row == 0) {
            DiscountViewController *disSubVC = [[DiscountViewController alloc]init];
            UINavigationController *disSubNa = [[UINavigationController alloc]initWithRootViewController:disSubVC];
            DisSubTwoModel *disSubModel = [self.disSubArray firstObject];
            disSubVC.navigationItem.title = disSubModel.title;
            disSubVC.discountString = disSubModel.url;
            [self presentViewController:disSubNa animated:YES completion:^{
                
                
            }];
        }else if (indexPath.row == 2){

            UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"数据维护!" message:nil preferredStyle:UIAlertControllerStyleAlert];
            
            [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil]];
            [self presentViewController:alert animated:YES completion:nil];
        
        
        }
    }
    
    else if (indexPath.section == 2){
        HotTripViewController *hotTripVC = [[HotTripViewController alloc]init];
        UINavigationController *hotTripNa = [[UINavigationController alloc]initWithRootViewController:hotTripVC];
        ThirdLModel *hotModel = [self.hotArray objectAtIndex:indexPath.row];
        hotTripVC.navigationItem.title = hotModel.title;
        hotTripVC.hotTripString = hotModel.view_url;
        [self presentViewController:hotTripNa animated:YES completion:^{
            
        }];
    }
    
}


//===================
#pragma mark tableView每个分区要显示的行数(cell的个数)必须实现的方法之一
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    //return 50;//(50是行数)
    if (section == 0) {
        return 3;
    }else if(section == 1){
        return 3;
        
    
    }
    
   return  self.hotArray.count;

}


#pragma mark 必须实现的方法之2,作用是每显示一个cell都会执行这个方法.
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
//为什么每一步都要比下一步少1步
//第一个区的每行对应cell "发现下一站"
    if (indexPath.section == 0) {
        if (indexPath.row == 0) {
            
           //对应注册
   NextFirstRowTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:nextFirstCell];
            //利用model建立一个对象
            NextFourModel *nextModel = [self.nstationArray firstObject];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            cell.subjectNext = nextModel;

        return cell;
        }else if (indexPath.row == 1){
            
            NextSecondRowTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:nextSecondCell];
           
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            
            cell.tempArray = self.nstationArray;
           
            
            
            cell.nextStationBlock = ^(NSInteger index){
                
                NextStationViewController *stationVC = [[NextStationViewController alloc]init];
                UINavigationController *stationNaVC = [[UINavigationController alloc]initWithRootViewController:stationVC];
                
                
                if (index == 0) {
                    NextFourModel *model = self.nstationArray[1];
                    stationVC.nextString = model.url;
                    
                }
                if (index == 1) {
                    NextFourModel *model = self.nstationArray[2];
                    stationVC.nextString = model.url;
                }
                
                [self presentViewController:stationNaVC animated:YES completion:^{
                    
                    
                }];
               
            };
            
            return cell;
        }
        
        
        NextThirdRowTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:nextThirdCell];
      
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
        
    } else if (indexPath.section == 1)//"抢特价折扣"
    {
        if (indexPath.row == 0) {
            DisFirstTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:disFirstCell];
            DisSubTwoModel *disSubModel = [self.disSubArray firstObject];
            cell.disSubModel = disSubModel;
              cell.selectionStyle = UITableViewCellSelectionStyleNone;
            
            return cell;
        }else if(indexPath.row == 1){
        
            DisSecondTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:disSecondCell];
            cell.allArray = self.discountArray;
             cell.selectionStyle = UITableViewCellSelectionStyleNone;
            
            [cell setDiscountBlock:^(NSInteger index) {
                
                UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"数据维护!" message:nil preferredStyle:UIAlertControllerStyleAlert];
                
                [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil]];
                [self presentViewController:alert animated:YES completion:nil];
                
            }];
            
            
            
            return cell;
        
        }
        DisThirdTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:disThirdCell];
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    
    }
    
    
    //============"热门游记"的cell还没有赋值
    HotTripTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:hotTripCell];
   
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    cell.hotModel = self.hotArray[indexPath.row];


    return cell;
}














- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
